package main.java;

/**
 * @author: 大怪
 * @email: 962527441@qq.com
 */
public class Test81_N皇后问题 {
    public static int buildHouses(int n) {
        // write code here
        int[] house = new int[n];
        test(house,0,n);
        return count;
    }
    static int count = 0;

    private static boolean place(int[] arr, int s) {
        for(int i = 0; i < s; i++) {
            if((arr[i] == arr[s]) || (Math.abs(i-s) == Math.abs(arr[i]-arr[s]))) {
                return false;
            }
        }

        return true;
    }

    public static void test(int[] arr, int i, int n) {
        if(i >= n) {
            ++count;
        } else {
            for(int j = 0; j < n; j++) {
                arr[i] = j;
                if(place(arr, i)) {
                    test(arr, i+1, n);
                }
            }
        }
    }

    public static void main(String[] args) {
        int i = buildHouses(4);
        System.out.println(i);
    }
}
